#include <cassert>

#include "StateMachine.h"
#include "State.h"
#include "Event.h"

namespace lib {

  void         StateMachine::setContext(Context* context) { context_ = context; }
  void         StateMachine::setState(State::Code code)   { state_ = State::make(code); }
  const State* StateMachine::getState() const { return state_; }

  void StateMachine::start() {
    assert(state_ != nullptr); 
    assert(context_ != nullptr); 
    state_->onEnter(context_); 
  }

  void StateMachine::handle(const E_Comein&        e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Repair&        e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Lend&          e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Expire&        e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Extend&        e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Return&        e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Reserve&       e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Cancelreserve& e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Repaired&      e) { state_ = state_->handle(e,context_); }
  void StateMachine::handle(const E_Dispose&       e) { state_ = state_->handle(e,context_); }

}

